import os
import shutil


def get_test_tmp_dir(test_data_dir: os.PathLike, sub_path: os.PathLike = '.',
                     create_dir=True, exist_ok=True, clean_dir=True):
    """获取临时的测试目录

    Args:
        test_data_dir (os.PathLike): 测试数据目录
        sub_path (os.PathLike, optional): 新建的测试目录的子目录. Defaults to '.'.
        create_dir (bool, optional): 新建目录. Defaults to True.
        exist_ok (bool, optional): 允许目录存在. Defaults to True.
        clean_dir (bool, optional): 清空目录. Defaults to True.

    Returns:
        _type_: 创建的临时目录
    """
    base_name = os.path.basename(test_data_dir)
    parent_dir = os.path.dirname(test_data_dir)
    test_dir = os.path.join(parent_dir, f'.{base_name}', sub_path)
    if clean_dir:
        shutil.rmtree(test_dir, ignore_errors=True)
    if create_dir:
        os.makedirs(test_dir, exist_ok=exist_ok)
    return test_dir

